package model

import "time"

// 定义数据模型

type RegisterUser struct {
	Username   string `json:"username" bidding:"required,min=1,max=18"`
	Email      string `json:"email" bidding:"required,email"`
	Password   string `json:"password" bidding:"required,min=6,max=20"`
	RePassword string `json:"re_password" bidding:"required,min=6,max=20"`
}

type LoginUser struct {
	Username string `json:"username" bidding:"required,min=1,max=18"`
	Password string `json:"password" bidding:"required,min=6,max=20"`
}

type User struct {
	UserID   int64  `json:"user_id" bidding:"required,min=1,max=18" gorm:"primary_key"`
	Username string `json:"username" bidding:"required,min=1,max=18"`
	Password string `json:"password" bidding:"required,min=6,max=20"`
	Email    string `json:"email" bidding:"required,email"`
	//Token    string `json:"token"`
	//CreateTime time.Time `json:"create_time" bidding:"required"`
	//UpdateTime time.Time `json:"update_time" bidding:"required"`
}

type Community struct {
	CommunityID   int64  `json:"id" gorm:"primary_key"`
	CommunityName string `json:"name"`
}

type CommunityDetail struct {
	CommunityID   int64     `json:"id" gorm:"primary_key"`
	CommunityName string    `json:"name"`
	Introduction  string    `json:"introduction"`
	CreateTime    time.Time `json:"create_time"`
}

type Post struct {
	PostID      int64  `json:"id" binding:"required" gorm:"primary_key"`
	AuthorID    int64  `json:"author_id"`
	CommunityID int64  `json:"community_id"`
	Title       string `json:"title" binding:"required,min=1,max=128"`
	Content     string `json:"content" binding:"required,min=1,max=65535"`
	CreateTime  string `json:"create_time"`
}

// PostList 获取帖子列表query string参数
type PostList struct {
	CommunityID int64  `json:"community_id" form:"community_id"`   // 可以为空
	Page        int64  `json:"page" form:"page" example:"1"`       // 页码
	Size        int64  `json:"size" form:"size" example:"10"`      // 每页数据量
	Order       string `json:"order" form:"order" example:"score"` // 排序依据
}

type ApiPostDetail struct {
	AuthorName       string             `json:"author_name"` // 作者
	VoteNum          int64              `json:"vote_num"`    // 投票数
	*Post                               // 嵌入帖子结构体
	*CommunityDetail `json:"community"` // 嵌入社区结构体
}

type VoteData struct {
	PostID    string `json:"post_id" binding:"required"`               // 帖子ID
	Direction int    `json:"direction,string" binding:"oneof=1 0 -1" ` // 赞成票(1)还是反对票(-1)取消投票(0)
}

type VoteDataTemp struct {
	PostID    int64 `json:"post_id" binding:"required"`               // 帖子ID
	Direction int   `json:"direction,string" binding:"oneof=1 0 -1" ` // 赞成票(1)还是反对票(-1)取消投票(0)
}
